﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoastalClimbing.Code;

namespace CoastalClimbing.Auth
{
    public partial class SEO : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
                this.BindInfo();
        }

        private void BindInfo()
        {
            ddlMetaType.DataTextField = "DESCRIPTION";
            ddlMetaType.DataValueField = "ID";
            ddlMetaType.DataSource = DAL.MetaTypesSelect();
            ddlMetaType.DataBind();

            ddlPage.DataTextField = "DESCRIPTION";
            ddlPage.DataValueField = "ID";
            ddlPage.DataSource = DAL.PagesGet();
            ddlPage.DataBind();

            grvSEO.DataSource = DAL.MetaSelect();
            grvSEO.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtDescription.Text))
            {
                
                DAL.MetaCreate(txtDescription.Text, Guid.Parse(ddlPage.SelectedItem.Value), Guid.Parse(ddlMetaType.SelectedItem.Value));
                this.BindInfo();

                txtDescription.Text = "";
            }
        }
    }
}